package md.mru.frontend.models;

import org.primefaces.model.menu.DefaultMenuItem;
import org.primefaces.model.menu.DefaultMenuModel;
import org.primefaces.model.menu.MenuModel;

import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import java.io.Serializable;

/**
 * @author sergiu.marin
 * @since 30/05/2014.
 */
@Deprecated
@ManagedBean
@SessionScoped
public class TreeContextMenuModel implements Serializable {

    private static final long serialVersionUID = -2406396515543574781L;

    /*@ManagedProperty(value = "#{treeAdministrationBean}")
    private TreeAdministrationBean treeAdministrationBean;*/
    private MenuModel menuModel;

    @PostConstruct
    public void init() {
        menuModel = new DefaultMenuModel();
        DefaultMenuItem menuItem = new DefaultMenuItem("Adauga");
        menuItem.setIcon("ui-icon-plus");
        menuItem.setCommand("#{treeAdministrationBean.setupTreeNodeDialog('add')}");
        menuItem.setOncomplete("PF('treeNodeDialog').show()");
        menuItem.setUpdate(":add-node-form");
        menuItem.setId("menu-item-to-change");
        menuItem.setStyleClass("test");
        menuModel.addElement(menuItem);

        /*if (this.isFolderType()) {
            menuItem = new DefaultMenuItem("Adauga");
            menuItem.setIcon("ui-icon-plus");
            menuItem.setCommand("#{treeAdministrationBean.setupTreeNodeDialog('add')}");
            menuItem.setOncomplete("PF('treeNodeDialog').show()");
            menuItem.setUpdate(":add-node-form");
            menuModel.addElement(menuItem);
        } else {
            menuItem = new DefaultMenuItem("Ataseaza dosar");
            menuItem.setIcon("ui-icon-plus");
            menuItem.setCommand("#{treeAdministrationBean.displayAttachFolderDialog}");
            menuItem.setOncomplete(this.getOnCompleteJs());
            menuItem.setUpdate(":new-ordin-form");
            menuModel.addElement(menuItem);
        }*/

        menuItem = new DefaultMenuItem("Editeaza");
        menuItem.setIcon("ui-icon-pencil");
        menuItem.setCommand("#{treeAdministrationBean.setupTreeNodeDialog('edit')}");
        menuItem.setOncomplete("PF('treeNodeDialog').show()");
        menuItem.setUpdate(":add-node-form");
        menuModel.addElement(menuItem);

    }

    /*private boolean isFolderType() {
        TreeNodeModelDto nodeModel = (TreeNodeModelDto) this.treeAdministrationBean.getSelectedTreeNode().getData();
        return nodeModel.getTreeNodeType().getFunctionType().equals(FunctionType.FOLDER);
    }*/

    /*private String getOnCompleteJs() {
        TreeNodeModelDto nodeModel = (TreeNodeModelDto) this.treeAdministrationBean.getSelectedTreeNode().getData();
        if (!nodeModel.getTreeFolders().isEmpty()) {
            if (nodeModel.getTreeFolders().size() > 1) {
                return "PF('no-new-person').show()";
            }
            if (nodeModel.getTreeFolders().iterator().next().isActive()) {
                return "PF('already-active-person').show()";
            }
        }
        return "PF('treeAddOrder').show()";
    }*/

    public MenuModel getMenuModel() {
        return menuModel;
    }

    /*public void setTreeAdministrationBean(TreeAdministrationBean treeAdministrationBean) {
        this.treeAdministrationBean = treeAdministrationBean;
    }*/
}
